home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / Mac Satellite.sit / Mac Satellite / MacSeason9 v1.7 / MacSeason9v1.7 / MacSeason9.src / vcDialogs.c < prev    next >
C/C++ Source or Header  |  1995-08-14  |  5KB  |  206 lines

  1. #include "MacSeason9.h"
  2.  
  3. extern vcPrefs prgPrefs;
  4. extern unsigned long shutDownTime;
  5. extern unsigned char *msgStrings[10];
  6.  
  7. void StateDispatch( void );
  8.  
  9. void LoadPrefs( void )
  10. {
  11.     Handle theRes;
  12.     
  13.     theRes=GetResource(PREFRESTYPE,PREFRESID);
  14.     if (theRes) {
  15.         HLock(theRes);
  16.         BlockMove(*theRes, &prgPrefs, sizeof(prgPrefs) );
  17.         HUnlock(theRes);
  18.         ReleaseResource(theRes);
  19.     } else {    /* build preferences the first time */
  20.         prgPrefs.decode            = 0;    /* No decode delay */
  21.         prgPrefs.processReset    = 140;    /* Reset Delay = 140 */
  22.         prgPrefs.byte            = 0;    /* No Byte Delay */
  23.         prgPrefs.kernelCount    = 999;    /* No please wait bytes */
  24.         prgPrefs.whichPort        = kPortA; /* Use port A (modem) */
  25.         prgPrefs.debug            = 0;    /* Don't show Traffic Info window */
  26.         prgPrefs.tvMsgs            = 1;    /* Display messages on TV */
  27.         prgPrefs.fullDecode        = 1;    /* Decode wether answer is required or not */
  28.         prgPrefs.endless        = 0;    /* Allow background tasks */
  29.         prgPrefs.normDisplay    = 0;    /* Minimal display on computer */
  30.     }
  31. }
  32.  
  33. void SavePrefs( void )
  34. {
  35.     Handle theRes;
  36.     
  37.     theRes=GetResource(PREFRESTYPE,PREFRESID);
  38.     if (GetHandleSize(theRes) != sizeof(prgPrefs) ) {
  39.         SetHandleSize(theRes, sizeof(prgPrefs));
  40.     }
  41.     if (theRes) {
  42.         HLock(theRes);
  43.         BlockMove(&prgPrefs,*theRes, sizeof(prgPrefs) );
  44.         HUnlock(theRes);
  45.         ChangedResource(theRes);
  46.     } else {
  47.         theRes=NewHandle(sizeof(prgPrefs));
  48.         HLock(theRes);
  49.         BlockMove(&prgPrefs,*theRes, sizeof(prgPrefs) );
  50.         HUnlock(theRes);
  51.         AddResource(theRes,PREFRESTYPE,PREFRESID, msgStrings[0]);
  52.     }
  53.     WriteResource(theRes);
  54.     ReleaseResource(theRes);
  55. }
  56.  
  57.  
  58. pascal void MyItemProc(WindowPtr theDlg, short theItem)
  59. {
  60.     Rect    iRect;
  61.     Handle    iHndl;
  62.     short    iType;
  63.     
  64.     GetDItem(theDlg,1,&iType,&iHndl,&iRect);
  65.     PenSize(3,3);
  66.     InsetRect(&iRect,-4,-4);
  67.     FrameRoundRect(&iRect,16,16);
  68. }
  69.  
  70. pascal Boolean MyDlgFilter(DialogPtr theDlg,EventRecord *theEvent, short *itemHit )
  71. {
  72.     unsigned char    theChar;
  73.     
  74.     StateDispatch();
  75.     if ( theEvent->what != keyDown )
  76.         return(FALSE);
  77.  
  78.     theChar=(theEvent->message) & charCodeMask;
  79.     if ((theChar==0x0D)||(theChar==0x03)) {
  80.         *itemHit=ok;
  81.         return(TRUE);
  82.     } else {
  83.         if ((theChar==0x1B)||((theChar==0x2E)&&((theEvent->modifiers) & cmdKey))) {
  84.             *itemHit = cancel;
  85.             return( TRUE );
  86.         }
  87.     }
  88.     return(FALSE);
  89. }
  90.  
  91. void SetPrefs(void)
  92. {
  93.     GrafPtr        savePort;
  94.     DialogPtr    myDlg;
  95.     short        theItem;
  96.     short        iType;
  97.     Handle        iHandle;
  98.     Rect        iRect;
  99.     short        checkBox[20], radioButton;
  100.     Str255        numStr;
  101.     long        theNum;
  102.     
  103.     GetPort(&savePort);
  104.     myDlg=GetNewDialog(dlgDelays, 0L,(WindowPtr) -1L);
  105.     GetDItem(myDlg,3,&iType,&iHandle,&iRect);
  106.     SetDItem(myDlg,3,iType, (ProcPtr )MyItemProc,&iRect);
  107.  
  108.     checkBox[dlyDecode]    = prgPrefs.decode;
  109.     checkBox[dlyReset]    = prgPrefs.processReset;
  110.     checkBox[dlyByte]    = prgPrefs.byte;
  111.     checkBox[dlyKernCnt]= prgPrefs.kernelCount;
  112.  
  113.     for (theItem = dlyFirstInp; theItem <= dlyLastInp; theItem++ ) {
  114.         theNum=(long )checkBox[theItem];
  115.         NumToString(theNum, numStr);
  116.         GetDItem(myDlg, theItem, &iType, &iHandle, &iRect);
  117.         SetIText(iHandle, numStr);
  118.     }
  119.     radioButton = prfModem + prgPrefs.whichPort;
  120.     GetDItem(myDlg, prfModem, &iType, &iHandle, &iRect);
  121.     SetCtlValue((ControlHandle)iHandle, (radioButton == prfModem));
  122.     GetDItem(myDlg, prfPrinter, &iType, &iHandle, &iRect);
  123.     SetCtlValue((ControlHandle)iHandle, (radioButton == prfPrinter));
  124.     SelIText(myDlg,dlyDecode, 0, 32767);
  125.     SetPort(myDlg);
  126.     ShowWindow(myDlg);
  127.     do {
  128.         ModalDialog( MyDlgFilter, &theItem);
  129.         switch (theItem) {
  130.             case prfModem:
  131.             case prfPrinter:
  132.                 radioButton = theItem;
  133.                 GetDItem(myDlg, prfModem, &iType, &iHandle, &iRect);
  134.                 SetCtlValue((ControlHandle)iHandle, (radioButton == prfModem));
  135.                 GetDItem(myDlg, prfPrinter, &iType, &iHandle, &iRect);
  136.                 SetCtlValue((ControlHandle)iHandle, (radioButton == prfPrinter));
  137.                 break;
  138.         }
  139.     } while (theItem>2);
  140.     if (theItem==ok) {
  141.         for (theItem = dlyFirstInp; theItem <= dlyLastInp; theItem++ ) {
  142.             GetDItem(myDlg, theItem, &iType, &iHandle, &iRect);
  143.             GetIText(iHandle, numStr);
  144.             StringToNum(numStr, &theNum);
  145.             checkBox[theItem] = theNum;
  146.         }
  147.         prgPrefs.decode            = checkBox[dlyDecode];
  148.         prgPrefs.processReset    = checkBox[dlyReset];
  149.         prgPrefs.byte            = checkBox[dlyByte];
  150.         prgPrefs.kernelCount    = checkBox[dlyKernCnt];
  151.         
  152.         radioButton -= prfModem;
  153.         if (radioButton != prgPrefs.whichPort) {
  154.             prgPrefs.whichPort = radioButton;
  155.             CloseDownSerials();
  156.             InitializeVC(prgPrefs.whichPort);
  157.         }
  158.     }
  159.     DisposDialog(myDlg);
  160.     SetPort(savePort);
  161. }
  162.  
  163.  
  164. void SetShutdown(void)
  165. {
  166.     GrafPtr        savePort;
  167.     DialogPtr    myDlg;
  168.     short        theItem;
  169.     short        iType;
  170.     Handle        iHandle;
  171.     Rect        iRect;
  172.     long        shutdownValue;
  173.     Str255        numStr;
  174.     long        theNum;
  175.     
  176.     GetPort(&savePort);
  177.     myDlg=GetNewDialog(dlgShutdown, 0L,(WindowPtr) -1L);
  178.     GetDItem(myDlg,3,&iType,&iHandle,&iRect);
  179.     SetDItem(myDlg,3,iType, (ProcPtr )MyItemProc,&iRect);
  180.  
  181.     shutdownValue = 120;
  182.     NumToString(shutdownValue, numStr);
  183.     GetDItem(myDlg, shdTime, &iType, &iHandle, &iRect);
  184.     SetIText(iHandle, numStr);
  185.  
  186.     SelIText(myDlg, shdTime, 0, 32767);
  187.     SetPort(myDlg);
  188.     ShowWindow(myDlg);
  189.     do {
  190.         ModalDialog( MyDlgFilter, &theItem);
  191.     } while (theItem>2);
  192.     if (theItem==ok) {
  193.         GetDItem(myDlg, shdTime, &iType, &iHandle, &iRect);
  194.         GetIText(iHandle, numStr);
  195.         StringToNum(numStr, &shutdownValue);
  196.         
  197.         shutDownTime = (shutdownValue << 6);
  198.         shutDownTime -= (shutdownValue << 2); /*  * (64 - 4) */
  199.         shutDownTime += Time;
  200.     } else {
  201.         shutDownTime = 0;
  202.     }
  203.     DisposDialog(myDlg);
  204.     SetPort(savePort);
  205. }
  206.